package com.bsj.travel.util;

import javax.annotation.Resource;
import java.util.Random;

/**
 * @author LiJiaXin
 * @version 1.0.0
 * @description SecretKeyCreateUtil
 * @time 2024/4/7 15:33
 */
public class SecretKeyCreateUtil {

    private static final String CHAR_LOWER = "abcdefghijklmnopqrstuvwxyz";
    private static final String CHAR_UPPER = CHAR_LOWER.toUpperCase();
    private static final String NUMBERS = "0123456789";
    //秘钥长度
    private static final int APPID_LENGTH = 24;
    private static final String SEPARATOR = "-"; // 可以使用任何你想要的分隔符

    private static final String ALL_CHARACTERS = CHAR_LOWER + CHAR_UPPER + NUMBERS;
    private static final int ALL_CHARACTERS_LENGTH = ALL_CHARACTERS.length();

    private static Random random = new Random();

    public static void main(String[] args) {
        System.out.println("生成的随机APPID是: " + generateRandomAppId());
    }

    public static String generateRandomAppId() {
        StringBuilder appIdBuilder = new StringBuilder();

        // 生成APPID的前半部分
        for (int i = 0; i < APPID_LENGTH / 2; i++) {
            int randomIndex = random.nextInt(ALL_CHARACTERS_LENGTH);
            appIdBuilder.append(ALL_CHARACTERS.charAt(randomIndex));
        }

        // 生成APPID的后半部分
        for (int i = 0; i < APPID_LENGTH / 2; i++) {
            int randomIndex = random.nextInt(ALL_CHARACTERS_LENGTH);
            appIdBuilder.append(ALL_CHARACTERS.charAt(randomIndex));
        }

        return appIdBuilder.toString();
    }

}
